﻿using App.Model;
using App.Untiys;
using Sunny.UI;
using System.Drawing;
using System.Windows.Forms;

namespace App.Desk.UserControls
{
    public partial class PailButton : UIUserControl
    {
        public SysPail PailInfo { get; set; }
        public PailButton()
        {
            InitializeComponent();
            toolTip.SetToolTip(upBarPail, "鼠标右键更多操作", "温馨提示");
        }

        private void UIFlowItem_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            //e.Graphics.FillEllipse(Color.Lime, new Rectangle(10, 10, 20, 20));
            //e.Graphics.DrawString(Text, Font, ForeColor, new Rectangle(35, 0, Width, 40), ContentAlignment.MiddleLeft);
            e.Graphics.DrawLine(ForeColor, 10, 40, Width - 20, 40);
            //e.Graphics.DrawString("1#", Font, ForeColor, new Rectangle(10, 40, Width, Height - 40), ContentAlignment.MiddleCenter);
        }

        public void SetInfo()
        {
            txtInfo.Text = PailInfo.PailName;
            utpHeader.Text = $"{PailInfo.Current_Value}/{PailInfo.Threshold_Value}";
            if (PailInfo.Threshold_Value != 0)
                upBarPail.Value = ((PailInfo.Current_Value.ToDoubleEx() / PailInfo.Threshold_Value.ToDoubleEx()) * 100).ToIntEx();
        }

        private void upBarPail_DoubleClick(object sender, System.EventArgs e)
        {
            //UIMessageBox.Show(PailInfo.Id.ToStringEx());
        }

        private void upBarPail_Click(object sender, System.EventArgs e)
        {

        }

        private void upBarPail_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                upBarPail.ShowContextMenuStrip(menuPailSet, 0, 0);
            }
        }

        private void 修改ToolStripMenuItem_Click(object sender, System.EventArgs e)
        {
            //try
            //{
            //    new Monitor.FrmPailSet().ShowDialog();
            //    //刷新父窗体 显示事件
            //    if (this.Parent != null)
            //        if (this.Parent.Parent != null)
            //            if (this.Parent.Parent.Parent != null)
            //                ((FrmPail)this.Parent.Parent.Parent).BindListForThread();
            //}
            //catch
            //{

            //}
        }

        private void utpHeader_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                utpHeader.ShowContextMenuStrip(menuPailSet, 0, 0);
            }
        }

        private void txtInfo_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                txtInfo.ShowContextMenuStrip(menuPailSet, 0, 0);
            }
        }

        //设置当前桶
        public void SetCurrPail()
        {
            utpHeader.TitleColor = Color.LightBlue;
        }

        //设置满桶
        public void SetFullPail()
        {
            utpHeader.TitleColor = Color.Red;
        }
    }
}
